﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Serialization;
using System.ComponentModel;

namespace UniCT.LinkShareWpf.Model
{
    // XmlRoot è applicato solo alla classe che quando serializzata rappresenta l'elemento di apertura e chiusura dell'xml

    [Serializable]
    [XmlRoot("Node")]
    public class Node : INotifyPropertyChanged
    {

        #region Private
        private string url;
        private DateTime lastAliveRequest;
        private long lastPing;

        #endregion

        [XmlIgnore]
        public Uri Uri
        {
            get { return new Uri(Url); }
        }

        [XmlAttribute("Url")]
        public string Url
        {
            get { return url; }
            set
            {
                url = value;
                this.OnPropertyChanged("Url");
            }
        }

        [XmlAttribute("LastAliveRequest")]
        public DateTime LastAliveRequest
        {
            get { return lastAliveRequest; }
            set
            {
                lastAliveRequest = value;
                this.OnPropertyChanged("LastAliveRequest");
            }
        }

        [XmlAttribute("LastPing")]
        public long LastPing
        {
            get { return lastPing; }
            set
            {
                lastPing = value;
                this.OnPropertyChanged("LastPing");
            }
        }

        #region INotifyPropertyChanged Support

        protected void OnPropertyChanged(string propertyName)
        {
            if (this.PropertyChanged != null) this.PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
        }

        public event PropertyChangedEventHandler PropertyChanged;

        #endregion

    }

}
